package com.hxy.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxy.dao.*;
import com.hxy.pojo.Folk;
import com.hxy.pojo.Stuffinfo;
import com.hxy.pojo.model.GetUtilPagerequest;
import com.hxy.pojo.vo.StuffinfoAddVo;
import com.hxy.pojo.vo.StuffinfoShowByIdVo;
import com.hxy.pojo.vo.StuffinfoVo;
import com.hxy.service.StuffinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author feiyu
 * 员工信息业务层StuffinfoServiceImpl
 */
@Service
public class StuffinfoServiceImpl  implements StuffinfoService {
    @Autowired
    private StuffinfoMapper stuffinfoMapper;
    @Autowired
    private FolkMapper folkMapper;
    @Autowired
    private EstatusMapper EStatusMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private KulturMapper kulturMapper;
    @Autowired
    private VisageMapper visageMapper;
    @Autowired
    private BranchMapper branchMapper;
    @Autowired
    private EstatusMapper estatusMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return stuffinfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(StuffinfoAddVo record) {
        return stuffinfoMapper.insert(record);
    }

    @Override
    public StuffinfoVo selectByPrimaryKey(Integer id) {
        return stuffinfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Stuffinfo> selectAll() {
        return stuffinfoMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Stuffinfo record) {
        return stuffinfoMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<StuffinfoVo> selectByPageInfo(Integer page, int limit, String sex, String stuffName, String worklength, String branch) {
        PageHelper.startPage(page,limit);
        GetUtilPagerequest getutilPagerequest = new GetUtilPagerequest(sex, stuffName, worklength, branch);
        List<StuffinfoVo> voList=stuffinfoMapper.selectByPageInfo(getutilPagerequest);
        for (StuffinfoVo stuffinfoVo : voList) {
            System.out.println(stuffinfoVo+"4444444444444");
        }
        PageInfo<StuffinfoVo> stuffinfoVoPageInfo=new PageInfo<>(voList);
        return  stuffinfoVoPageInfo;
    }

    @Override
    public StuffinfoAddVo selectByIdeVo(int eid) {
        StuffinfoAddVo stuffinfupdateVo =stuffinfoMapper.selectByIdVo(eid);
        //根据id查民族
        if (stuffinfupdateVo!=null){
            return stuffinfupdateVo;
        }
        else{
            return null;
        }

    }

    @Override
    public StuffinfoShowByIdVo selectByIdShowAllNamesByEID(Integer eidByUsername) {
        StuffinfoAddVo selectOneById=stuffinfoMapper.selectByIdShowAllNamesByEID(eidByUsername);
        System.out.println(selectOneById+"666666666666666666666666");
        if(selectOneById!=null){
            StuffinfoShowByIdVo selectByIdShowAllNamesByEID=new StuffinfoShowByIdVo();
            selectByIdShowAllNamesByEID.setFolkname(folkMapper.selectByPrimaryKey(selectOneById.getFolk()).getFolkname());
            selectByIdShowAllNamesByEID.setKulturname(kulturMapper.selectByPrimaryKey(selectOneById.getKultur()).getKulturname());
            selectByIdShowAllNamesByEID.setVisagename(visageMapper.selectByPrimaryKey(selectOneById.getVisage()).getVisagename());
            selectByIdShowAllNamesByEID.setBranchname(branchMapper.selectByPrimaryKey(selectOneById.getBranch()).getBranchname());
            selectByIdShowAllNamesByEID.setStatusname(estatusMapper.selectByPrimaryKey(selectOneById.getStatusid()).getStatuName());
            selectByIdShowAllNamesByEID.setBusinessname(businessMapper.selectByPrimaryKey(selectOneById.getBusiness()).getBusinessname());

            selectByIdShowAllNamesByEID.setId(selectOneById.getId());
            selectByIdShowAllNamesByEID.setStuffname(selectOneById.getStuffname());
            selectByIdShowAllNamesByEID.setBirthday(selectOneById.getBirthday());
            selectByIdShowAllNamesByEID.setMarriage(selectOneById.getMarriage());
            selectByIdShowAllNamesByEID.setSex(selectOneById.getSex());
            selectByIdShowAllNamesByEID.setIdcard(selectOneById.getIdcard());
            selectByIdShowAllNamesByEID.setWorklength(selectOneById.getWorklength());
            selectByIdShowAllNamesByEID.setMonthpay(selectOneById.getMonthpay());
            selectByIdShowAllNamesByEID.setBankcard(selectOneById.getBankcard());
            selectByIdShowAllNamesByEID.setGraduateschool(selectOneById.getGraduateschool());
            selectByIdShowAllNamesByEID.setPhone(selectOneById.getPhone());
            selectByIdShowAllNamesByEID.setSpeciality(selectOneById.getSpeciality());
            selectByIdShowAllNamesByEID.setGraduatedate(selectOneById.getGraduatedate());
            selectByIdShowAllNamesByEID.setPhoto(selectOneById.getPhoto());
            selectByIdShowAllNamesByEID.setAddress(selectOneById.getAddress());
            selectByIdShowAllNamesByEID.setCity(selectOneById.getCity());
            selectByIdShowAllNamesByEID.setStartpactdate(selectOneById.getStartpactdate());
            selectByIdShowAllNamesByEID.setEndpactdate(selectOneById.getEndpactdate());
            return selectByIdShowAllNamesByEID;
        }
        else{
            return null;
        }

    }
}
